package org.lemon.cla.enums;

import com.baomidou.mybatisplus.annotation.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import org.lemon.cla.exception.BusinessException;

public enum UserRoleEnum implements IEnum<String> {
    STUDENT("学生"),
    ADMIN("管理员");

    private final String description;

    UserRoleEnum(String description) {
        this.description = description;
    }

    @Override
    @JsonValue
    public String getValue() {
        return this.description;
    }

    public String getDescription() {
        return description;
    }

    @JsonCreator
    public static UserRoleEnum fromDescription(String description) {
        for (UserRoleEnum role : UserRoleEnum.values()) {
            if (role.getDescription().equals(description)) {
                return role;
            }
        }
        throw new BusinessException(HttpStatusEnum.UNSUPPORTED_TYPE.getCode(),"非法的枚举: "+description);
    }
}